﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TanWeb.Models.Entities;
using TanWeb.Helpers;
using TanWeb.Models.DataAccess;
using TanWeb.Controllers.Business.Infrastructure;

namespace TanWeb.Controllers.Business
{
    public class HomeBusiness : BaseBusiness
    {
        public List<MenuItem> GetMenuItems()
        {
            logger.Info("\tStart Business: Home; Action: GetMenuItems");

            List<MenuItem> menuItems = new List<MenuItem>();
            ItemGroupDataAccess groupAccess = new ItemGroupDataAccess(this.DbContext);
            SubItemGroupDataAccess subGroupAccess = new SubItemGroupDataAccess(this.DbContext);

            try
            {
                List<ItemGroup> itemGroups = groupAccess.GetAllItemGroup();

                foreach (ItemGroup itemGroup in itemGroups)
                {
                    List<SubItemGroup> subItemGroups = subGroupAccess.GetSubItemsByGroupId(itemGroup.id);
                    MenuItem mnuItem = new MenuItem(itemGroup, subItemGroups);
                    menuItems.Add(mnuItem);
                }
            }
            catch (Exception ex)
            {
                logger.Info("\tError Business: Home; Action: GetMenuItems", ex);
            }

            logger.Info("\tEnd Business: Home; Action: GetMenuItems");

            return menuItems;
        }

        public List<ProductProfile> GetProductInfo()
        {
            logger.Info("\tStart Business: Home; Action: GetProductInfo");

            ProductDataAccess access = new ProductDataAccess(this.DbContext);
            List<ProductProfile> productProfile = new List<ProductProfile>();
            
            try
            {
                productProfile = access.GetProductInfo(string.Empty, string.Empty);
            }
            catch (Exception ex)
            {
                logger.Info("\tError Business: Home; Action: GetProductInfo", ex);
            }

            logger.Info("\tEnd Business: Home; Action: GetProductInfo");

            return productProfile;
        }
    }
}